package leetcodes;

import sun.nio.cs.ext.ISO2022_CN;

import java.util.*;

public class Main2 {

    public static void main(String[] args) {
        System.out.println(multiply("33111","222"));
    }



    


    public static String multiply(String num1, String num2) {
        int len = Math.max(num1.length(),num2.length());
        int result = 0;
        int temp=0;
        for (int a=len-1;a>=0;a--){
            int n1 = len-a>num1.length() ? 0:((int)num1.charAt(a)-48);
            int n2 = len-a>num2.length() ? 0:((int)num2.charAt(a)-48);
            int sum = n1*n2;
            result += (sum%10+temp)*Math.pow(10,len-1-a);
            temp= sum/10;
        }
        return String.valueOf(result);
    }


     static class MyCom implements Comparator<Integer>{
         @Override
         public int compare(Integer o1, Integer o2) {
             return o2-o1;
         }
     }
    public static long solve (int n, int[] cutIn) {
        // write code here
        ArrayList<Integer> arr = new ArrayList<>();
        for (int a=0;a<n;a++){
            arr.add(n-a);
        }

        for (int a:cutIn){
            arr.remove(a);
            arr.add(a);
        }
        for (int a:arr){
            System.out.print(a);
        }
        System.out.println();
        int res = 0;
        for (int b=0;b<arr.size();b++){
            if (arr.get(n-b-1) != b+1){
                res++;
            }
        }
        return res;
    }


    public static String addStrings(String num1, String num2) {
        long res = 0;
        int maxLen = Math.max(num1.length(),num2.length());
        int a1= 0;
        int a2= 0;
        for (int a=0;a<maxLen;a++){
            res= res*10;
            a1 = a>=num1.length()? 0 : (int)num1.charAt(num1.length()-a-1)-48;
            a2 = a>=num2.length()? 0 : (int)num2.charAt(num2.length()-a-1)-48;
            res +=(a1+a2);
        }
        StringBuilder str= new StringBuilder();
        str.append(res);
        if (res>10){
            return  str.reverse().toString();
        }
        return str.toString();
    }

    /*
    实现一个算法，确定一个字符串 s 的所有字符是否全都不同。
    * */
    public static boolean isUnique(String astr) {
        //去重  首先考虑使用hash表,这里使用数组

        int[] arr = new int[26];
        char[] arrs = astr.toCharArray();
        for (int a = 0; a < arrs.length; a++) {
            int index = (int) arrs[a] - 97;
            if (arr[index] == 1) {
                return false;
            }
            arr[index]++;
        }
            return true;
    }

    /*
    给你一个包含 n 个整数的数组 nums，判断 nums 中是否存在三个元素 a，b，c ，使得 a + b + c = 0 ？请你找出所有满足条件且不重复的三元组。
    //请注意不重复  数字相同顺序不同也视为重复
    * */
    public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> list = new LinkedList<>();
        for (int x = 0;x<nums.length-1;x++){
            for (int y=0;y<nums.length -x;y++){
                if (nums[x] > nums[y]){
                    int temp =nums[x];
                    nums[x] = nums[y];
                    nums[y] = temp;
                }
            }
        }
        for (int a= 0;a<nums.length-2;a++){
            for (int b=a+1;b<nums.length-1;b++){
                for (int c=b+1;c<nums.length;c++){
                    if (nums[a] + nums[b] +nums[c] == 0){
                        List<Integer> list1 = new LinkedList<>();
                        list1.add(nums[a]);
                        list1.add(nums[b]);
                        list1.add(nums[c]);
                        list.add(list1);
                    }
                }
            }
        }
        return list;
    }

}
